/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
*  \class	TBasicGrid
*  \author 	Jari Saarinen
*  \date 	Fri Jun 09 15:20:24 2006

*  \version: 0.1  
*/

#ifndef T_BASIC_GRID_H
#define T_BASIC_GRID_H

#include <stdio.h>
#include "gridType.h"

class TBasicGrid
{
private: 
	TBasePixel *data;				// The grid data

protected:
	unsigned int Nx;				// The size of the grid in pixels in X-direction (WIDTH)
	unsigned int Ny;				// The size of the grid in pixels in Y-direction (HEIGHT)
	unsigned int data_size;			// The data size in bytes
	
	TBasicGrid();					// For pre - initialization

	/**
	* This function initializes the Class variables.
	*/
	void initBasicGrid(unsigned int Nx, unsigned int Ny);
public:
	/**
	* The constructor
	* Takes the grid size in x and y directions as input. 
	* @param Nx		The grid size in pixels in x direction (width)
	* @param Ny		The grid size in pixels in y direction (height)
	*/
	TBasicGrid(unsigned int Nx, unsigned int Ny);
	virtual ~TBasicGrid();
	/**
	* Get number of grid pixels in x-direction
	*/
	unsigned int getNX();
	/**
	* Get number of grid pixels in x-direction
	*/
	unsigned int getNY();
	/**
	* Get the reserved memory size
	*/
	unsigned int getDataSize();
	
	/**
	* Get the pixel from grid position x, y
	*/
	TBasePixel getPixel(unsigned int x, unsigned int y);
	
	/**
	* Set the content of a pixel in to the grid position x,y
	* The x and y are given in GRID coordinate system (i.e. relative)
	* Not in absolute (0,0 is the up left corner in this coordinate system)
	*/	
	int setPixel(TBasePixel P, unsigned int x, unsigned int y);
	
	
	
	/**
	* Copy the data at once 
	* @param *P		the pointer to destination. Memory MUST be reserved. 
	* @return		the bytes copied  
	*/
	int getPixelData(TBasePixel *P);
	
	/**
	* Copies the given memory to data field. Be careful with the sizes
	* @param *P		The input data. Make sure it is correstly sized
	* @param size	The size of the input data, just to be sure!
	* @return 0, if ok else -1
	*/
	int setPixelData(TBasePixel *P, unsigned int size);

	/**
	* Sets the whole data into given value
	*/
	void initPixelData(unsigned char value);

	/**
	* Copies the data byte by byte to textfile with white space between bytes and line feed
	* after sizeof(TBasePixel) * Nx
	* @param filename the file to save the data
	*/
	void toTextFile(const char *filename);

	/**
	* Prints the internal variables to *f
	* @param *f the pointer to file stream
	*/
	void printBasicGridInfo(FILE *f);
	/**
	* Get direct pointer to the data!!!
	*/
	TBasePixel *getDataPtr();
};          


#endif


